package org.blog.model;

import org.blog.util.StringHelper;

public class ModelArticle extends BaseModel implements ValidateModel{
//	private Integer id;
//	private String username;//20
	private String title;//15
	private String content;//30000
	private Integer isDraft=0;//1
	private Integer catalogId;//8
	private Long createTime;//13
	private Long actionTime;//13
	private Integer action;//状态 1：添加，2：修改，3：删除

//	public Integer getId() {
//		return id;
//	}
//
//	public void setId(Integer id) {
//		this.id = id;
//	}
//
//	public String getUsername() {
//		return username;
//	}
//
//	public void setUsername(String username) {
//		this.username = username;
//	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	public Integer getIsDraft() {
		return isDraft;
	}

	public void setIsDraft(Integer isDraft) {
		this.isDraft = isDraft;
	}

	public Integer getCatalogId() {
		return catalogId;
	}

	public void setCatalogId(Integer catalogId) {
		this.catalogId = catalogId;
	}

	public Long getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Long createTime) {
		this.createTime = createTime;
	}

	public Long getActionTime() {
		return actionTime;
	}

	public void setActionTime(Long actionTime) {
		this.actionTime = actionTime;
	}

	public Integer getAction() {
		return action;
	}

	public void setAction(Integer action) {
		this.action = action;
	}

	@Override
	public boolean validate(ActionType type) {
		if (ActionType.ADD.equals(type)) {
			if (StringHelper.isEmptyTrim(getTitle())) {
				return false;
			}
		} else if(ActionType.MODIFY.equals(type)){
			if (StringHelper.isEmptyTrim(getTitle())) {
				return false;
			}
		}else if(ActionType.DELETE.equals(type)){
			if (getId()==null) {
				return false;
			}
		}else if(ActionType.GET.equals(type)){
			if (getId()==null) {
				return false;
			}
		}else if(ActionType.GET_PARENT.equals(type)){
			if (getCatalogId()==null) {
				return false;
			}
		}
		return true;
	}

}
